home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 June / PersonalComputerWorld-June2009-CoverdiscCD.iso / Software / Freeware / Adobe AIR 1.5.1 / AdobeAIRInstaller.exe / setup.swf / scripts / mx / utils / StringUtil.as < prev    next >
Encoding:
Text File  |  2009-02-12  |  2.5 KB  |  105 lines

  1. package mx.utils
  2. {
  3.    import mx.core.mx_internal;
  4.    
  5.    use namespace mx_internal;
  6.    
  7.    public class StringUtil
  8.    {
  9.       mx_internal static const VERSION:String = "3.0.0.0";
  10.       
  11.       public function StringUtil()
  12.       {
  13.          super();
  14.       }
  15.       
  16.       public static function trim(param1:String) : String
  17.       {
  18.          if(param1 == null)
  19.          {
  20.             return "";
  21.          }
  22.          var _loc2_:int = 0;
  23.          while(isWhitespace(param1.charAt(_loc2_)))
  24.          {
  25.             _loc2_++;
  26.          }
  27.          var _loc3_:int = param1.length - 1;
  28.          while(isWhitespace(param1.charAt(_loc3_)))
  29.          {
  30.             _loc3_--;
  31.          }
  32.          if(_loc3_ >= _loc2_)
  33.          {
  34.             return param1.slice(_loc2_,_loc3_ + 1);
  35.          }
  36.          return "";
  37.       }
  38.       
  39.       public static function isWhitespace(param1:String) : Boolean
  40.       {
  41.          switch(param1)
  42.          {
  43.             case " ":
  44.             case "\t":
  45.             case "\r":
  46.             case "\n":
  47.             case "\f":
  48.                return true;
  49.             default:
  50.                return false;
  51.          }
  52.       }
  53.       
  54.       public static function substitute(param1:String, ... rest) : String
  55.       {
  56.          var _loc4_:Array = null;
  57.          if(param1 == null)
  58.          {
  59.             return "";
  60.          }
  61.          var _loc3_:uint = uint(rest.length);
  62.          if(_loc3_ == 1 && rest[0] is Array)
  63.          {
  64.             _loc4_ = rest[0] as Array;
  65.             _loc3_ = _loc4_.length;
  66.          }
  67.          else
  68.          {
  69.             _loc4_ = rest;
  70.          }
  71.          var _loc5_:int = 0;
  72.          while(_loc5_ < _loc3_)
  73.          {
  74.             param1 = param1.replace(new RegExp("\\{" + _loc5_ + "\\}","g"),_loc4_[_loc5_]);
  75.             _loc5_++;
  76.          }
  77.          return param1;
  78.       }
  79.       
  80.       public static function trimArrayElements(param1:String, param2:String) : String
  81.       {
  82.          var _loc3_:Array = null;
  83.          var _loc4_:int = 0;
  84.          var _loc5_:int = 0;
  85.          if(param1 != "" && param1 != null)
  86.          {
  87.             _loc3_ = param1.split(param2);
  88.             _loc4_ = int(_loc3_.length);
  89.             _loc5_ = 0;
  90.             while(_loc5_ < _loc4_)
  91.             {
  92.                _loc3_[_loc5_] = StringUtil.trim(_loc3_[_loc5_]);
  93.                _loc5_++;
  94.             }
  95.             if(_loc4_ > 0)
  96.             {
  97.                param1 = _loc3_.join(param2);
  98.             }
  99.          }
  100.          return param1;
  101.       }
  102.    }
  103. }
  104.  
  105.